package com.example.springioc;

import com.example.springioc.Component.User;
import com.example.springioc.Controller.UserController;
import com.example.springioc.Repository.UserRepository;
import com.example.springioc.Service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;

@SpringBootApplication
public class SpringIocApplication {

    public static void main(String[] args) {
        //类型
       ApplicationContext context =SpringApplication.run(SpringIocApplication.class, args);
        UserController bean = context.getBean(UserController.class);
        bean.sayhi();
//
//        UserController bean1 = context.getBean(UserController.class);
//        bean1.sayhi();
        //System.out.println(bean1);

        //通过名字获取bean
//        UserService userService = (UserService) context.getBean("userService");
//        userService.doService();

        //通过类型＋名字
//        UserRepository userRepository = context.getBean("userRepository", UserRepository.class);
//        userRepository.doRespository();
//        User bean1 = context.getBean(User.class);
//        System.out.println(bean1);
        //bean注解获取
//        User user = (User) context.getBean("user");
//        System.out.println(user);
        //注入依赖以后
//        UserController bean3= context.getBean(UserController.class);
//        bean3.sayhi();

    }

}
